{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "54c3418b",
   "metadata": {},
   "source": [
    "# Python 注释\n",
    "注释可用于解释 Python 代码。\n",
    "\n",
    "注释可用于使代码更具可读性。\n",
    "\n",
    "注释可用于在测试代码时阻止执行。 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "436f1e43",
   "metadata": {},
   "source": [
    "# 创建注释"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf11b4db",
   "metadata": {},
   "source": [
    "注释以 # 开头，Python 会忽略它们："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e87346d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, World!\n"
     ]
    }
   ],
   "source": [
    "#This is a comment\n",
    "print(\"Hello, World!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5f1daf9",
   "metadata": {},
   "source": [
    "注释可以放在一行的末尾，Python 将忽略该行的其余部分："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "750b3b2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, World!\n"
     ]
    }
   ],
   "source": [
    "print(\"Hello, World!\") #This is a comment"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "009eca9d",
   "metadata": {},
   "source": [
    "注释不一定是解释代码的文本，它还可以用来阻止 Python 执行代码： "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "99429845",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cheers, Mate!\n"
     ]
    }
   ],
   "source": [
    "#print(\"Hello, World!\")\n",
    "print(\"Cheers, Mate!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "336e6bab",
   "metadata": {},
   "source": [
    "# 多行注释"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2042a0c7",
   "metadata": {},
   "source": [
    "Python 并没有真正的多行注释语法。\n",
    "要添加多行注释，您可以为每一行插入 #："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d6e98ce6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, World!\n"
     ]
    }
   ],
   "source": [
    "#This is a comment\n",
    "#written in\n",
    "#more than just one line\n",
    "print(\"Hello, World!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7ad65ec",
   "metadata": {},
   "source": [
    "您可以使用多行字符串。\n",
    "由于 Python 将忽略未分配给变量的字符串文字，因此您可以在代码中添加多行字符串（三引号），并将您的注释放在其中："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "94d934aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "This is a comment\n",
    "written in\n",
    "more than just one line\n",
    "\"\"\"\n",
    "print(\"Hello, World!\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
